package com.shuoyue.ycgk.ui.recruitment;

import com.shuoyue.ycgk.base.BasePresenter;
import com.shuoyue.ycgk.base.BaseResult;
import com.shuoyue.ycgk.base.BaseView;
import com.shuoyue.ycgk.net.RetrofitClient;
import com.shuoyue.ycgk.net.base.ApiSubscriber;
import com.shuoyue.ycgk.net.gsondefaultadapter.Optional;

import io.reactivex.Observable;


public interface FocusChangeContract {
    interface View extends BaseView {
        void success(boolean isFocuse);

        void enableCollectButton();

        void disAbleCollectButton();
    }

    class Presenter extends BasePresenter<View> {
        Model model = new Model();

        public void collectionNotice(int id, int type, boolean isCollect) {
            mView.disAbleCollectButton();
            apply(model.collectionNotice(id, type, isCollect ? 2 : 1))
                    .subscribe(new ApiSubscriber<Optional<String>>(mView, this) {
                        @Override
                        public void onNext(Optional<String> recruitmentMainInfoOptional) {
                            super.onNext(recruitmentMainInfoOptional);
                            mView.success(!isCollect);
                        }

                        @Override
                        public void onFinish() {
                            super.onFinish();
                            mView.enableCollectButton();
                        }
                    });
        }
    }

    class Model {
        public Observable<BaseResult<String>> collectionNotice(int id, int type, int actionType) {
            return RetrofitClient.getInstance().getApi().collectionNotice(id, type, actionType);
        }
    }
}
